// src/services/ResultService.js
import BaseService from "./BaseService";
import { setResultIdCache } from "./storage";

class ResultService extends BaseService {
  async getResultList(type = 'all') {
    const url = type === 'processing' 
      ? process.env.REACT_APP_API_PROCESSING_LIST 
      : process.env.REACT_APP_API_RESULT_LIST;
    
    return this.request(url, 'POST', {}, true);
  }

  async startScraping(params) {
    const result = await this.request(
      process.env.REACT_APP_API_START_SCRAPE,
      'POST',
      { list: params },
      true
    );

    if (result.success && result.data) {
      const resultId = result.data.resultId || "";
      if (resultId) {
        setResultIdCache(resultId);
      }
    }

    return result;
  }
}

export const resultService = new ResultService();